package com.windoent.yugioh.adapter.brvah;

import android.graphics.Color;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.windoent.yugioh.R;
import com.windoent.yugioh.bean.PanFaListData;
import com.windoent.yugioh.utils.BaseMethod;
import com.windoent.yugioh.utils.SimpleUtils;
import com.windoent.yugioh.widget.RoundImageView;

/**
 * author : robert
 * date   : 2021/5/6 15:26
 * desc   :
 */
public class PanFaRecordAdapter extends BaseQuickAdapter<PanFaListData.DataBean.ResBean, BaseViewHolder> {

    public PanFaRecordAdapter() {
        super(R.layout.item_list_pan_fa_record, null);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, PanFaListData.DataBean.ResBean item) {
        PanFaListData.DataBean.RefereeBean referee_info = item.getReferee_info();
        RoundImageView iv_avatar = helper.getView(R.id.iv_avatar);
        if (referee_info != null) {
            helper.setText(R.id.tv_name, BaseMethod.notNullDefaultValueNull(referee_info.getNickname()));
            SimpleUtils.loadImageForView(getContext(), iv_avatar, referee_info.getAvatar(), R.drawable.img_official_avatar_android);
        } else {
            iv_avatar.setBackgroundResource(R.drawable.img_official_avatar_android);
            helper.setText(R.id.tv_name, getContext().getString(R.string.string_no_data));
        }
        helper.setText(R.id.tv_lun, BaseMethod.notNullDefaultValueNull(item.getRounds()))
                .setText(R.id.tv_type, BaseMethod.notNullDefaultValueNull(item.getType_name()));

        LinearLayout parent = helper.getView(R.id.ll_parent);
        int layoutPosition = helper.getLayoutPosition();
        parent.setBackgroundColor(layoutPosition % 2 == 1 ? Color.parseColor("#21243A") : Color.TRANSPARENT);
    }
}